package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    // 查询地址列表
    List<AddressBook> findList(AddressBook addressBook);

    // 新增地址
    @Insert("insert into address_book values (null,#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void save(AddressBook addressBook);

    // 设置非默认地址
    @Update("update address_book set is_default=0 where user_id=#{userId}")
    void updateByUserId(Long userId);

    // 更新地址
    void update(AddressBook addressBook);

    //回显地址
    @Select("select * from address_book where id=#{id}")
    AddressBook findById(Long id);


    //删除地址
    @Delete("delete from address_book where id=#{id}")
    void deleteById(Long id);
}
